<?php


namespace app\api\controller;


use app\common\controller\Api;
use app\common\model\CommentModel;

class Comment extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['getCommentPageList'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];


    /**
     * 获取评论列表
     */
    public function getCommentPageList()
    {
        $mold = $this->request->request('mold');
        $mold_id = $this->request->request('mold_id');
        $page = $this->request->request('page',1);
        $limit = $this->request->request('limit',5);
        $data = CommentModel::getPageList($mold,$mold_id,$page,$limit);
        $this->success($data['msg'], $data['data'], $data['code']);
    }

    /**
     * 发布评论
     */
    public function postComment()
    {
        $mold = $this->request->request('mold');
        $mold_id = $this->request->request('mold_id');
        $content = $this->request->request('content');
        if(!$mold || !$mold_id || !$content) {
            $this->error('参数不能为空', [], 40001);
        }
        $user_id = $this->auth->id;
        $data = CommentModel::postComment($user_id,$mold,$mold_id,$content);
        $this->success($data['msg'], $data['data'], $data['code']);
    }
}